package com.example.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.config.R;
import com.example.entity.Orders;
import com.example.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("page")
    public R<Page> page(int page,int pageSize,Long number,String beginTime,String endTime){
        Page<Orders> pageInof=new Page<>(page,pageSize);
        LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>();
        if (number!=null){
            queryWrapper.like(Orders::getNumber,number);
        }
        if (beginTime!=null){
            queryWrapper.ge(Orders::getOrderTime,beginTime);
        }
        if (endTime!=null){
            queryWrapper.le(Orders::getOrderTime,endTime);
        }
        queryWrapper.orderByDesc(Orders::getOrderTime);
        orderService.page(pageInof,queryWrapper);
        return R.success(pageInof);

    }
}
